package common

import (
	"encoding/json"
	"fmt"
	"net/http"
)

const (
	APPCODE = "fbe677e7f7664ee8aac2a6efa62b515c"
	URL     = "http://eid.shumaidata.com/eid/check"
)

// 实名验证
func Auth(username string, code string) string {
	//https://eid.shumaidata.com/eid/check?idcard=350301******9422&name=%E5%86%AF%E5%AE%9D%E5%AE%9D
	payload := URL + "?idcard=" + code + "&name=" + username
	client := &http.Client{}
	req, _ := http.NewRequest("POST", payload, nil)
	//Authorization:APPCODE 你自己的AppCode
	req.Header.Set("Authorization", "APPCODE "+APPCODE)
	res, _ := client.Do(req)
	defer res.Body.Close()

	var m map[string]interface{}
	json.NewDecoder(res.Body).Decode(&m)
	fmt.Println(m)
	r, _ := m["result"].(map[string]interface{})
	return r["description"].(string)
}
